/*
 * FreeRTOS V202104.00
 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://www.FreeRTOS.org
 * http://aws.amazon.com/freertos
 *
 * 1 tab == 4 spaces!
 */


 /******************************************************************************
 *
 * http://www.FreeRTOS.org/cli
 *
 ******************************************************************************/


/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"

/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"

#include "cli-command.h"

#ifndef configINCLUDE_QUERY_HEAP_COMMAND
	#define configINCLUDE_QUERY_HEAP_COMMAND 1
#endif

/*
 * The function that registers the commands that are defined within this file.
 */
void vRegisterSampleCLICommands( void );

/*
 * Implements the task-stats command.
 */
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
 * Implements the GT101 command.
 */
static BaseType_t prvGwShowCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvReadRegCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvWriteRegCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvSpiToolCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvcontrol_modeCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvGpioCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvDmaTxCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvDmaTxTestCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvRapidioCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );

static BaseType_t prvLoadBit1Command( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
static BaseType_t prvLoadBit2Command( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );


/*
 * Implements the echo-three-parameters command.
 */
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );


/* GT101 command line command */
static const CLI_Command_Definition_t xGwShow =
{
	"show",
	"\r\nshow:\r\n -- show state in device\r\n",
	prvGwShowCommand, /* The function to run. */
	0
};

static const CLI_Command_Definition_t xReadReg =
{
	"reg_read",
	"\r\nreg_read <addr 0x>:\r\n -- Expects 1 parameters\r\n",
	prvReadRegCommand, /* The function to run. */
	1
};

static const CLI_Command_Definition_t xWriteReg =
{
	"reg_write",
	"\r\nreg_write <addr 0x> <data 0x>:\r\n -- Expects 2 parameters\r\n",
	prvWriteRegCommand, /* The function to run. */
	2
};

static const CLI_Command_Definition_t xSpiTool =
{
	"spi_tool",
	"\r\nspi_tool <dev 0x> <data 0x>:\r\n 0x1 hmc7044 \r\n 0x2 dac \r\n 0x4 lmx_adc \r\n 0x8 lmx_dac \r\n 0x10 adc \r\n",
	prvSpiToolCommand, /* The function to run. */
	2
};

static const CLI_Command_Definition_t xControlMode =
{
	"control_mode",
	"\r\ncontrol_mode <mode 0x>:\r\n 0x0 loopback \r\n 0x1 normal \r\n 0x2 rx_out \r\n 0x3 tx_out \r\n",
	prvcontrol_modeCommand, /* The function to run. */
	1
};

static const CLI_Command_Definition_t xControlGpio =
{
	"gpio",
	"\r\ngpio <value 0x> <addr 0x>:\r\n -- set gpio value\r\n",
	prvGpioCommand, /* The function to run. */
	2
};

static const CLI_Command_Definition_t xDmaTx =
{
	"dma_tx",
	"\r\ndma_tx <str>:\r\n -- Expects 1 parameters\r\n",
	prvDmaTxCommand, /* The function to run. */
	1
};

static const CLI_Command_Definition_t xDmaTxTest =
{
	"dma_test",
	"\r\ndma_test <test_cnt decimal> <clear_cnt decimal>:\r\n -- Expects 2 parameters\r\n",
	prvDmaTxTestCommand, /* The function to run. */
	2
};

static const CLI_Command_Definition_t xRapidIo =
{
	"rapidio_show",
	"\r\nrapidio_show:\r\n -- show rapidIO recv in device\r\n",
	prvRapidioCommand, /* The function to run. */
	0
};

static const CLI_Command_Definition_t xLoadBit1 =
{
	"load_bit1",
	"\r\nload_bit1:\r\n -- load bit 1\r\n",
	prvLoadBit1Command, /* The function to run. */
	0
};

static const CLI_Command_Definition_t xLoadBit2 =
{
	"load_bit2",
	"\r\nload_bit2:\r\n -- load bit 2\r\n",
	prvLoadBit2Command, /* The function to run. */
	0
};




/* Structure that defines the "task-stats" command line command.  This generates
a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats =
{
	"task_stats", /* The command string to type. */
	"\r\ntask_stats:\r\n -- Displays a table showing the state of each FreeRTOS task\r\n",
	prvTaskStatsCommand, /* The function to run. */
	0 /* No parameters are expected. */
};

/* Structure that defines the "echo_3_parameters" command line command.  This
takes exactly three parameters that the command simply echos back one at a
time. */
static const CLI_Command_Definition_t xThreeParameterEcho =
{
	"echo-3-parameters",
	"\r\necho-3-parameters <param1> <param2> <param3>:\r\n -- Expects three parameters, echos each in turn\r\n",
	prvThreeParameterEchoCommand, /* The function to run. */
	3 /* Three parameters are expected, which can take any value. */
};


/*-----------------------------------------------------------*/

void vRegisterSampleCLICommands( void )
{
	/* Register all the command line commands defined immediately above. */
	FreeRTOS_CLIRegisterCommand( &xTaskStats );
	FreeRTOS_CLIRegisterCommand( &xGwShow );	
	FreeRTOS_CLIRegisterCommand( &xReadReg );
	FreeRTOS_CLIRegisterCommand( &xWriteReg );
	FreeRTOS_CLIRegisterCommand( &xSpiTool );
	FreeRTOS_CLIRegisterCommand( &xControlMode ); 
	FreeRTOS_CLIRegisterCommand( &xControlGpio );
	FreeRTOS_CLIRegisterCommand( &xDmaTx );
	FreeRTOS_CLIRegisterCommand( &xDmaTxTest );
	FreeRTOS_CLIRegisterCommand( &xRapidIo );
	FreeRTOS_CLIRegisterCommand( &xLoadBit1 );
	FreeRTOS_CLIRegisterCommand( &xLoadBit2 );

	// FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
}
/*-----------------------------------------------------------*/

static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *const pcHeader = "     State   Priority  Stack    #\r\n************************************************\r\n";
BaseType_t xSpacePadding;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	/* Generate a table of task stats. */
	strcpy( pcWriteBuffer, "Task" );
	pcWriteBuffer += strlen( pcWriteBuffer );

	/* Minus three for the null terminator and half the number of characters in
	"Task" so the column lines up with the centre of the heading. */
	configASSERT( configMAX_TASK_NAME_LEN > 3 );
	for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
	{
		/* Add a space to align columns after the task's name. */
		*pcWriteBuffer = ' ';
		pcWriteBuffer++;

		/* Ensure always terminated. */
		*pcWriteBuffer = 0x00;
	}
	strcpy( pcWriteBuffer, pcHeader );
	vTaskList( pcWriteBuffer + strlen( pcHeader ) );

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}

/*-----------------------------------------------------------*/

static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "The three parameters were:\r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		memset( pcWriteBuffer, 0x00, xWriteBufferLen );
		sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
		strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );
		strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );

		/* If this is the last of the three parameters then there are no more
		strings to return after this one. */
		if( uxParameterNumber == 3U )
		{
			/* If this is the last of the three parameters then there are no more
			strings to return after this one. */
			xReturn = pdFALSE;
			uxParameterNumber = 0;
		}
		else
		{
			/* There are more parameters to return after this one. */
			xReturn = pdTRUE;
			uxParameterNumber++;
		}
	}

	return xReturn;
}
/*-----------------------------------------------------------*/

static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "The parameters were:\r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		if( pcParameter != NULL )
		{
			/* Return the parameter string. */
			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
			strncat( pcWriteBuffer, ( char * ) pcParameter, ( size_t ) xParameterStringLength );
			strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );

			/* There might be more parameters to return after this one. */
			xReturn = pdTRUE;
			uxParameterNumber++;
		}
		else
		{
			/* No more parameters were found.  Make sure the write buffer does
			not contain a valid string. */
			pcWriteBuffer[ 0 ] = 0x00;

			/* No more data to return. */
			xReturn = pdFALSE;

			/* Start over the next time this command is executed. */
			uxParameterNumber = 0;
		}
	}

	return xReturn;
}
/*-----------------------------------------------------------*/


/* -------------------------------- GT101 Command ------------------------------- */


static BaseType_t prvReadRegCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvReadRegCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		memset( pcWriteBuffer, 0x00, xWriteBufferLen );
		// sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
		// strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );

		u32 address = stringToInt(pcParameter);
		u32 value = gw_ReadReg(address);
		sprintf( pcWriteBuffer, "%d : %s , ReadReg - address : 0x%x , value = 0x%x \r\n", ( int ) uxParameterNumber, pcParameter, address, value);

		if( uxParameterNumber == 1U )
		{
			xReturn = pdFALSE;
			uxParameterNumber = 0;
		}
	}

	return xReturn;
}

static BaseType_t prvWriteRegCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

static u32 value = 0x0;
static u32 address = 0x0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvWriteRegCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		if(uxParameterNumber == 1U){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			address = stringToInt(tmp_str);
			uxParameterNumber = uxParameterNumber + 1;
			xReturn = pdPASS;
		}else if( uxParameterNumber == 2U ){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			value = stringToInt(tmp_str);

			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			{
				gw_WriteReg(address,value);
				sprintf( pcWriteBuffer, "%s , WriteReg - address : 0x%x , value = 0x%x \r\n", pcCommandString, address, value);
			}
			xReturn = pdFALSE;
			uxParameterNumber = 0;
			value = 0x0;
			address = 0x0;
		}
	}

	return xReturn;
}

static BaseType_t prvSpiToolCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

static u32 data = 0x0;
static u32 slave_mask = 0x0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvSpiToolCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		if(uxParameterNumber == 1U){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			slave_mask = stringToInt(tmp_str);
			uxParameterNumber = uxParameterNumber + 1;
			xReturn = pdPASS;
		}else if( uxParameterNumber == 2U ){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			data = stringToInt(tmp_str);
			u8 rx_data = 0x0;
			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			if( cli_spi_cmd(data, slave_mask, &rx_data) != 0){
				sprintf( pcWriteBuffer, "spi cmd error !\r\n" );
			}else{
				sprintf( pcWriteBuffer, "spi_tool 0x%x 0x%x : rx_value = 0x%x\r\n", slave_mask, data, rx_data);
			}
			xReturn = pdFALSE;
			uxParameterNumber = 0;
			data = 0x0;
			slave_mask = 0x0;
		}
	}

	return xReturn;
}

static BaseType_t prvGwShowCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	memset( pcWriteBuffer, 0x00, xWriteBufferLen );
	cli_show(pcWriteBuffer);

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}

static BaseType_t prvcontrol_modeCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvcontrol_modeCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		memset( pcWriteBuffer, 0x00, xWriteBufferLen );
		// sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
		// strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );

		u32 mode = stringToInt(pcParameter);
		cli_control_mode(mode);
		sprintf( pcWriteBuffer, "%d : %s , control_mode - mode : 0x%x \r\n", ( int ) uxParameterNumber, pcParameter, mode);

		if( uxParameterNumber == 1U )
		{
			xReturn = pdFALSE;
			uxParameterNumber = 0;
		}
	}

	return xReturn;
}

static BaseType_t prvGpioCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

static u32 value = 0x0;
static u32 address = 0x0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvGpioCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		if(uxParameterNumber == 1U){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			value = stringToInt(tmp_str);
			uxParameterNumber = uxParameterNumber + 1;
			xReturn = pdPASS;
		}else if( uxParameterNumber == 2U ){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			address = stringToInt(tmp_str);

			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			{
				set_gpio_value(value,address);
				sprintf( pcWriteBuffer, "%s , gpio - value : 0x%x , address = 0x%x \r\n", pcCommandString, value, address);
			}
			xReturn = pdFALSE;
			uxParameterNumber = 0;
			value = 0x0;
			address = 0x0;
		}
	}

	return xReturn;
}

static BaseType_t prvDmaTxCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvDmaTxCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		memset( pcWriteBuffer, 0x00, xWriteBufferLen );

		if(cli_dma_send(pcParameter) != XST_SUCCESS){
			sprintf( pcWriteBuffer, "dma_tx -- XST_FAILURE \r\n");
		}else{
			sprintf( pcWriteBuffer, "%d : %s , dma_tx -- <str>\r\n", ( int ) uxParameterNumber, pcParameter);
		}

		if( uxParameterNumber == 1U )
		{
			xReturn = pdFALSE;
			uxParameterNumber = 0;
		}
	}

	return xReturn;
}

static BaseType_t prvDmaTxTestCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;

static u32 test_cnt = 0x0;
static u32 clear_cnt = 0x0;

	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	if( uxParameterNumber == 0 )
	{
		/* The first time the function is called after the command has been
		entered just a header string is returned. */
		sprintf( pcWriteBuffer, "prvDmaTxTestCommand : \r\n" );

		/* Next time the function is called the first parameter will be echoed
		back. */
		uxParameterNumber = 1U;

		/* There is more data to be returned as no parameters have been echoed
		back yet. */
		xReturn = pdPASS;
	}
	else
	{
		/* Obtain the parameter string. */
		pcParameter = FreeRTOS_CLIGetParameter
						(
							pcCommandString,		/* The command string itself. */
							uxParameterNumber,		/* Return the next parameter. */
							&xParameterStringLength	/* Store the parameter string length. */
						);

		/* Sanity check something was returned. */
		configASSERT( pcParameter );

		/* Return the parameter string. */
		if(uxParameterNumber == 1U){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			test_cnt = stringToDecimalInt(tmp_str);
			uxParameterNumber = uxParameterNumber + 1;
			xReturn = pdPASS;
		}else if( uxParameterNumber == 2U ){
			u8 tmp_str[10];
			memcpy(tmp_str, pcParameter, xParameterStringLength);
			tmp_str[xParameterStringLength] = '\0';
			clear_cnt = stringToDecimalInt(tmp_str);

			memset( pcWriteBuffer, 0x00, xWriteBufferLen );
			if( cli_dma_send_continue(test_cnt, clear_cnt) != XST_SUCCESS){
				sprintf( pcWriteBuffer, "dma_test -- XST_FAILURE \r\n");
			}else{
				sprintf( pcWriteBuffer, "%d : %s , dma_test -- test_cnt = %d, clear_cnt = %d\r\n", ( int ) uxParameterNumber, pcParameter, test_cnt, clear_cnt);
			}
			xReturn = pdFALSE;
			uxParameterNumber = 0;
			test_cnt = 0x0;
			clear_cnt = 0x0;
		}
	}

	return xReturn;
}

static BaseType_t prvRapidioCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	memset( pcWriteBuffer, 0x00, xWriteBufferLen );
	cli_rapidio(pcWriteBuffer);

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}

static BaseType_t prvLoadBit1Command( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	memset( pcWriteBuffer, 0x00, xWriteBufferLen );
	cli_switch_fpga(1);

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}

static BaseType_t prvLoadBit2Command( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
	/* Remove compile time warnings about unused parameters, and check the
	write buffer is not NULL.  NOTE - for simplicity, this example assumes the
	write buffer length is adequate, so does not check for buffer overflows. */
	( void ) pcCommandString;
	( void ) xWriteBufferLen;
	configASSERT( pcWriteBuffer );

	memset( pcWriteBuffer, 0x00, xWriteBufferLen );
	cli_switch_fpga(2);

	/* There is no more data to return after this single string, so return
	pdFALSE. */
	return pdFALSE;
}